<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="javascript速查手册(持续更新中), 风栾">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>javascript速查手册(持续更新中) | 风栾</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 4.2.1"><link rel="alternate" href="/atom.xml" title="风栾" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">风栾</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">风栾</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://zzh0312.gitee.io" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://zzh0312.gitee.io" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('https://img-blog.csdnimg.cn/20210104161132375.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p5ejAzMTIxOQ==,size_16,color_FFFFFF,t_70')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">javascript速查手册(持续更新中)</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/web%E5%89%8D%E7%AB%AF/">
                                <span class="chip bg-color">web前端</span>
                            </a>
                        
                            <a href="/tags/HTML%E5%9F%BA%E7%A1%80/">
                                <span class="chip bg-color">HTML基础</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/web%E5%89%8D%E7%AB%AF/" class="post-category">
                                web前端
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-12-27
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    7.7k
                </div>
                

                

                
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="javascript知识点速查"><a href="#javascript知识点速查" class="headerlink" title="javascript知识点速查"></a>javascript知识点速查</h2><h3 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h3><ul>
<li>数值（number）：整数和小数（比如<code>1</code>和<code>3.14</code>）</li>
<li>字符串（string）：文本（比如<code>Hello World</code>）。</li>
<li>布尔值（boolean）：表示真伪的两个特殊值，即<code>true</code>（真）和<code>false</code>（假）</li>
<li><code>undefined</code>：表示“未定义”或不存在，即由于目前没有定义，所以此处暂时没有任何值</li>
<li><code>null</code>：表示空值，即此处的值为空。</li>
<li>对象（object）：各种值组成的集合。</li>
<li>ES6 又新增了第七种 Symbol 类型的值，后续补充。</li>
</ul>
<p>通常，数值、字符串、布尔值这三种为基本数据类型；object，array，function为引用数据类型；至于undefined和null，一般看做两个特殊值。</p>
<h3 id="typeof与instanceof"><a href="#typeof与instanceof" class="headerlink" title="typeof与instanceof"></a>typeof与instanceof</h3><p><code>typeof</code>运算符可以返回一个值的数据类型（注意是小写的字符串类型）</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">typeof</span> <span class="token number">123</span> <span class="token comment" spellcheck="true">// "number"</span>
<span class="token keyword">typeof</span> <span class="token string">'123'</span> <span class="token comment" spellcheck="true">// "string"</span>
<span class="token keyword">typeof</span> <span class="token boolean">false</span> <span class="token comment" spellcheck="true">// "boolean"</span>
<span class="token keyword">typeof</span> <span class="token function">Symbol</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// symbol</span>
<span class="token keyword">function</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token keyword">typeof</span> f          <span class="token comment" spellcheck="true">// "function"</span>
<span class="token keyword">typeof</span> undefined    <span class="token comment" spellcheck="true">// "undefined"</span>
v       <span class="token comment" spellcheck="true">// ReferenceError: v is not defined</span>
<span class="token keyword">typeof</span> v       <span class="token comment" spellcheck="true">// "undefined"</span>
<span class="token keyword">typeof</span> window <span class="token comment" spellcheck="true">// "object"</span>
<span class="token keyword">typeof</span> <span class="token punctuation">{</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true">// "object"</span>
<span class="token keyword">typeof</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token comment" spellcheck="true">// "object"</span>

<span class="token keyword">typeof</span> <span class="token keyword">new</span> <span class="token class-name">Function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// function 有效</span>
<span class="token keyword">typeof</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//object 无效</span>
<span class="token keyword">typeof</span> <span class="token keyword">new</span> <span class="token class-name">RegExp</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//object 无效</span>

<span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
o <span class="token keyword">instanceof</span> <span class="token class-name">Array</span> <span class="token comment" spellcheck="true">// false</span>
a <span class="token keyword">instanceof</span> <span class="token class-name">Array</span> <span class="token comment" spellcheck="true">// true</span>

<span class="token keyword">typeof</span> <span class="token keyword">null</span> <span class="token comment" spellcheck="true">// "object"</span>

<span class="token keyword">null</span>是一个表示“空”的对象，转为数值时为<span class="token number">0</span>；undefined是一个表示<span class="token string">"此处无定义"</span>的原始值，转为数值时为<span class="token number">NaN</span>。</code></pre>
<h4 id="Number"><a href="#Number" class="headerlink" title="Number"></a>Number</h4><p>JavaScript不区分整数和浮点数，统一用Number表示，(JavaScript 语言的底层根本没有整数，所有数字都是小数（64位浮点数）)，以下都是合法的Number类型：</p>
<pre class=" language-js"><code class="language-js"><span class="token number">123</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 整数123</span>
<span class="token number">0.456</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 浮点数0.456</span>
<span class="token number">1.2345e3</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 科学计数法表示1.2345x1000，等同于1234.5</span>
<span class="token operator">-</span><span class="token number">99</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 负数</span>
<span class="token number">NaN</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// NaN表示Not a Number，          typeof NaN // 'number'</span>
<span class="token number">Infinity</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// Infinity表示无限大，当数值超过了JavaScript的Number所能表示的最大值时，就表示为Infinity</span>
十六进制用0x前缀和<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>，a<span class="token operator">-</span>f表示

根据国际标准 IEEE <span class="token number">754</span>，JavaScript 浮点数的<span class="token number">64</span>个二进制位，从最左边开始，是这样组成的。
第<span class="token number">1</span>位：符号位，<span class="token number">0</span>表示正数，<span class="token number">1</span>表示负数
第<span class="token number">2</span>位到第<span class="token number">12</span>位（共<span class="token number">11</span>位）：指数部分
第<span class="token number">13</span>位到第<span class="token number">64</span>位（共<span class="token number">52</span>位）：小数部分（即有效数字）
<span class="token operator">-</span><span class="token number">253</span>到<span class="token number">253</span>，都可以精确表示。大于<span class="token number">2</span>的<span class="token number">53</span>次方以后，整数运算的结果开始出现错误，由于<span class="token number">2</span>的<span class="token number">53</span>次方是一个<span class="token number">16</span>位的十进制数值，所以简单的法则就是，JavaScript 对<span class="token number">15</span>位的十进制数都可以精确处理。
Number<span class="token punctuation">.</span>MAX_VALUE <span class="token comment" spellcheck="true">// 1.7976931348623157e+308</span>
Number<span class="token punctuation">.</span>MIN_VALUE <span class="token comment" spellcheck="true">// 5e-324</span>

<span class="token number">0xff</span> <span class="token comment" spellcheck="true">// 255  十六进制</span>
<span class="token number">0o377</span> <span class="token comment" spellcheck="true">// 255  八进制</span>
<span class="token number">0b11</span> <span class="token comment" spellcheck="true">// 3    二进制</span>
<span class="token number">0888</span> <span class="token comment" spellcheck="true">// 888 有前导0不超过8则视为八进制</span>
<span class="token number">0777</span> <span class="token comment" spellcheck="true">// 511</span>

<span class="token operator">-</span><span class="token number">0</span> <span class="token operator">===</span> <span class="token operator">+</span><span class="token number">0</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token number">0</span> <span class="token operator">===</span> <span class="token operator">-</span><span class="token number">0</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token number">0</span> <span class="token operator">===</span> <span class="token operator">+</span><span class="token number">0</span> <span class="token comment" spellcheck="true">// true</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment" spellcheck="true">//将字符串转化为整数，如果参数不是字符串先转化为字符串再转换</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'8a'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 8</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'12**'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 12</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'12.34'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 12</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'15e2'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 15</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'15px'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 15</span>

<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'.3'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'+'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'+1'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1</span>
所以，parseInt的返回值只有两种可能，要么是一个十进制整数，要么是<span class="token number">NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'0x10'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 16</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'011'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 11</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token number">1000000000000000000000.5</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1</span>
<span class="token comment" spellcheck="true">// 等同于</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1e+21'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token number">0.0000008</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 8</span>
<span class="token comment" spellcheck="true">// 等同于</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'8e-7'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 8</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1000'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1000</span>
<span class="token comment" spellcheck="true">// 等同于</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1000'</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1000</span>

<span class="token comment" spellcheck="true">// parseInt方法还可以接受第二个参数（2到36之间），默认情况下，parseInt的第二个参数为10，即默认是十进制转十进制。如果第二个参数不是数值，会被自动转为一个整数。这个整数只有在2到36之间，才能得到有意义的结果，超出这个范围，则返回NaN。如果第二个参数是0、undefined和null，则直接忽略。</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1000'</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 8</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1000'</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 216</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1000'</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 512</span>

<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'10'</span><span class="token punctuation">,</span> <span class="token number">37</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'10'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'10'</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 10</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'10'</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 10</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'10'</span><span class="token punctuation">,</span> undefined<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 10</span>

<span class="token comment" spellcheck="true">// 对于二进制来说，1是有意义的字符，5、4、6都是无意义的字符，所以第一行返回1，第二行返回NaN。</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'1546'</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'546'</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment" spellcheck="true">//字符串转为浮点数</span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'314e-2'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 3.14</span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'0.0314E+2'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 3.14</span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'3.14more non-digit characters'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 3.14        </span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'\t\v\r12.34\n '</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 12.34        </span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'FF2'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN        </span>

<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">Number</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 1</span>

<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">Number</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 0</span>

<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
<span class="token function">Number</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 0</span>

<span class="token function">parseFloat</span><span class="token punctuation">(</span><span class="token string">'123.45#'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 123.45</span>
<span class="token function">Number</span><span class="token punctuation">(</span><span class="token string">'123.45#'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// NaN</span>
</code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token string">'Hello'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token comment" spellcheck="true">// 相当于</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token function">Number</span><span class="token punctuation">(</span><span class="token string">'Hello'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>

<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment" spellcheck="true">//isFinite方法返回一个布尔值，表示某个值是否为正常的数值</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token number">Infinity</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">Infinity</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span>undefined<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>


<span class="token function">eval</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//计算 JavaScript 字符串，并把它作为脚本代码来执行。</span></code></pre>
<h4 id="转义"><a href="#转义" class="headerlink" title="转义"></a>转义</h4><ul>
<li><code>\0</code> ：null（<code>\u0000</code>）</li>
<li><code>\b</code> ：后退键（<code>\u0008</code>）</li>
<li><code>\f</code> ：换页符（<code>\u000C</code>）</li>
<li><code>\n</code> ：换行符（<code>\u000A</code>）</li>
<li><code>\r</code> ：回车键（<code>\u000D</code>）</li>
<li><code>\t</code> ：制表符（<code>\u0009</code>）</li>
<li><code>\v</code> ：垂直制表符（<code>\u000B</code>）</li>
<li><code>\&#39;</code> ：单引号（<code>\u0027</code>）</li>
<li><code>\&quot;</code> ：双引号（<code>\u0022</code>）</li>
<li><code>\\</code> ：反斜杠（<code>\u005C</code>）</li>
</ul>
<h4 id="Base64转码"><a href="#Base64转码" class="headerlink" title="Base64转码"></a>Base64转码</h4><p>所谓 Base64 就是一种编码方法，可以将任意值转成 0～9、A～Z、a-z、<code>+</code>和<code>/</code>这64个字符组成的可打印字符。</p>
<p>JavaScript 原生提供两个 Base64 相关的方法。</p>
<ul>
<li><code>btoa()</code>：任意值转为 Base64 编码</li>
<li><code>atob()</code>：Base64 编码转为原来的值</li>
</ul>
<pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> string <span class="token operator">=</span> <span class="token string">'Hello World!'</span><span class="token punctuation">;</span>
<span class="token function">btoa</span><span class="token punctuation">(</span>string<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// "SGVsbG8gV29ybGQh"</span>
<span class="token function">atob</span><span class="token punctuation">(</span><span class="token string">'SGVsbG8gV29ybGQh'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// "Hello World!"</span></code></pre>
<h3 id="Object"><a href="#Object" class="headerlink" title="Object"></a>Object</h3><p>对象的所有键名都是字符串（ES6 又引入了 Symbol 值也可以作为键名），所以加不加引号都可以；如果键名是数值，会被自动转为字符串。</p>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">// 报错</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  1p<span class="token punctuation">:</span> <span class="token string">'Hello World'</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// 不报错</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token string">'1p'</span><span class="token punctuation">:</span> <span class="token string">'Hello World'</span><span class="token punctuation">,</span>
  <span class="token string">'h w'</span><span class="token punctuation">:</span> <span class="token string">'Hello World'</span><span class="token punctuation">,</span>
  <span class="token string">'p+q'</span><span class="token punctuation">:</span> <span class="token string">'Hello World'</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  p<span class="token punctuation">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token number">2</span> <span class="token operator">*</span> x<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
obj<span class="token punctuation">.</span><span class="token function">p</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 2</span>

<span class="token comment" spellcheck="true">//属性读取</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  p<span class="token punctuation">:</span> <span class="token string">'Hello World'</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

obj<span class="token punctuation">.</span>p <span class="token comment" spellcheck="true">// "Hello World"</span>
obj<span class="token punctuation">[</span><span class="token string">'p'</span><span class="token punctuation">]</span> <span class="token comment" spellcheck="true">// "Hello World"</span>

<span class="token comment" spellcheck="true">//属性查看所有</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
  key1<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  key2<span class="token punctuation">:</span> <span class="token number">2</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">// ['key1', 'key2']</span>

<span class="token comment" spellcheck="true">//属性是否存在：in 运算符</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span> p<span class="token punctuation">:</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token string">'p'</span> <span class="token keyword">in</span> obj <span class="token comment" spellcheck="true">// true</span>
<span class="token string">'toString'</span> <span class="token keyword">in</span> obj <span class="token comment" spellcheck="true">// true</span>
<span class="token keyword">in</span>运算符的一个问题是，它不能识别哪些属性是对象自身的，哪些属性是继承的。就像上面代码中，对象obj本身并没有toString属性，但是<span class="token keyword">in</span>运算符会返回<span class="token boolean">true</span>，因为这个属性是继承的。
这时，可以使用对象的hasOwnProperty方法判断一下，是否为对象自身的属性。
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">'toString'</span> <span class="token keyword">in</span> obj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span><span class="token string">'toString'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">//属性的遍历：for in循环</span>
<span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>a<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> b<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span> c<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token keyword">in</span> obj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'键名：'</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'键值：'</span><span class="token punctuation">,</span> obj<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">// 键名： a</span>
<span class="token comment" spellcheck="true">// 键值： 1</span>
<span class="token comment" spellcheck="true">// 键名： b</span>
<span class="token comment" spellcheck="true">// 键值： 2</span>
<span class="token comment" spellcheck="true">// 键名： c</span>
<span class="token comment" spellcheck="true">// 键值： 3</span>

<span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token punctuation">{</span> name<span class="token punctuation">:</span> <span class="token string">'老张'</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> key <span class="token keyword">in</span> person<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>person<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">// name</span></code></pre>
<h3 id="Function"><a href="#Function" class="headerlink" title="Function"></a>Function</h3><pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">//函数名式声明</span>
<span class="token keyword">function</span> <span class="token function">print</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">//赋值式声明</span>
<span class="token keyword">var</span> print <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//函数表达式声明,这里x只能在函数内部使用</span>
<span class="token keyword">var</span> print <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token function">x</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> x<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//构造函数声明</span>
<span class="token keyword">var</span> add <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Function</span><span class="token punctuation">(</span>
  <span class="token string">'x'</span><span class="token punctuation">,</span>
  <span class="token string">'y'</span><span class="token punctuation">,</span>
  <span class="token string">'return x + y'</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">// 等同于</span>
<span class="token keyword">function</span> <span class="token function">add</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p><em>ES6新增模板字符串${name}</em></p>
<h3 id="javascript输出"><a href="#javascript输出" class="headerlink" title="javascript输出"></a>javascript输出</h3><pre class=" language-js"><code class="language-js"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//警示框输出，包含确认按钮</span>
<span class="token function">prompt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//输入框弹出，包含输入框和确认按钮（取消返回null）</span>
<span class="token function">confirm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//确认框弹出，包含确认取消按钮（返回值true和false）</span>
document<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">"页面输出"</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true">//可以解析标签，\n无效要用&lt;br></span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"输出一条日志"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//最常用</span>
console<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">"输出一条信息"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">"输出一条警告"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">"输出一条错误"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">dir</span><span class="token punctuation">(</span><span class="token string">"打印当前对象"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">time</span><span class="token punctuation">(</span><span class="token string">"timer"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  console<span class="token punctuation">.</span><span class="token function">timeEnd</span><span class="token punctuation">(</span><span class="token string">"timer"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//运行耗时</span></code></pre>
<h3 id="Boolean对象"><a href="#Boolean对象" class="headerlink" title="Boolean对象"></a>Boolean对象</h3><pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Boolean</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">typeof</span> b <span class="token comment" spellcheck="true">// "object"</span>
b<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>

<span class="token function">Boolean</span><span class="token punctuation">(</span>undefined<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// false</span>

<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">'false'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token regex">/foo/</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>

使用双重否定转换为布尔值
<span class="token operator">!</span><span class="token operator">!</span>undefined <span class="token comment" spellcheck="true">// false</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token keyword">null</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token number">0</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token string">''</span> <span class="token comment" spellcheck="true">// false</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token number">NaN</span> <span class="token comment" spellcheck="true">// false</span>

<span class="token operator">!</span><span class="token operator">!</span><span class="token number">1</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token string">'false'</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">{</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true">// true</span>
<span class="token operator">!</span><span class="token operator">!</span><span class="token operator">/</span>foo<span class="token operator">/</span> <span class="token comment" spellcheck="true">// true</span></code></pre>
<h3 id="Array对象方法"><a href="#Array对象方法" class="headerlink" title="Array对象方法"></a>Array对象方法</h3><pre class=" language-js"><code class="language-js"><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true">//所有元素拼接为字符串,参数为连接符，不改变原数组!!</span>
    <span class="token keyword">var</span> arr<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    arr<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//"1,2,3"默认逗号分隔</span>
    arr<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">" "</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//"1 2 3"</span>
    arr<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//"123"</span>
        <span class="token comment" spellcheck="true">//String.split()是将字符串分割成数组</span>
        <span class="token comment" spellcheck="true">//Array.join()与String.split()互为逆运算</span>

<span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true">//数组翻转，返回逆序的数组，并且不带参数，改变原数组!!</span>
    <span class="token keyword">var</span> arr<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    arr<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//arr=[3,2,1]</span>
    arr<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//"3,2,1" 此时arr=[3,2,1]</span>

<span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true">//排序数组元素，不带参数默认以字母表顺序，一般传入判断函数，改变原数组！！</span>
    <span class="token keyword">var</span> arr1<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">6</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    arr1<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">{</span>
         <span class="token keyword">return</span> a<span class="token operator">-</span>b<span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">//升序排列 return b-a; //降序排列</span>
           <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr1<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">concat</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
   <span class="token comment" spellcheck="true">// 连接两个或多个数组，不影响原数组    返回新数组</span>
    <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    a<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//返回[1,2,3,4,5]</span>
    a<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//返回[1,2,3,4,5]</span>
    a<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//返回[1,2,3,4,5,6,7]</span>
    a<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 返回[1,2,3,4,5,[6,7]]</span>

<span class="token function">slice</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 
    <span class="token comment" spellcheck="true">//数组截取，不改变原数组，包头不包尾</span>
    <span class="token keyword">const</span> animals <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'ant'</span><span class="token punctuation">,</span> <span class="token string">'bison'</span><span class="token punctuation">,</span> <span class="token string">'camel'</span><span class="token punctuation">,</span> <span class="token string">'duck'</span><span class="token punctuation">,</span> <span class="token string">'elephant'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    animals<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//从索引号2起往后截取，包括2   Array ["camel", "duck", "elephant"]</span>
    animals<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">// 包括2不包括4      Array ["camel", "duck"]</span>
    animals<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">// -1到倒数第一个且不包括，-表示倒着数 Array ["bison", "camel", "duck"]</span>

<span class="token function">splice</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token comment" spellcheck="true">//删除数组指定元素，改变原数组，返回删除值</span>
    arr<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span>start<span class="token punctuation">,</span> count<span class="token punctuation">,</span> addElement1<span class="token punctuation">,</span> addElement2<span class="token punctuation">,</span> <span class="token operator">...</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//(位置，个数，插入元素)</span>
    <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token string">'c'</span><span class="token punctuation">,</span> <span class="token string">'d'</span><span class="token punctuation">,</span> <span class="token string">'e'</span><span class="token punctuation">,</span> <span class="token string">'f'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    a<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["e", "f"]</span>
    a <span class="token comment" spellcheck="true">// ["a", "b", "c", "d"]</span>

    a<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["e", "f"]</span>
    a <span class="token comment" spellcheck="true">// ["a", "b", "c", "d", 1, 2]</span>

    a<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["c", "d"]</span>

    <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    a<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// []</span>
    a <span class="token comment" spellcheck="true">// [1, 2, 1, 1]</span>

    <span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    a<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// [3, 4]</span>
    a <span class="token comment" spellcheck="true">// [1, 2]</span>

<span class="token comment" spellcheck="true">//添加删除数组元素方法</span>
<span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//追加，在数组末尾添加数组元素</span>
    <span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    arr<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">// push完毕后会返回新的数组长度   此例为7</span>

<span class="token function">unshift</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//在数组开头添加数组元素</span>
    arr<span class="token punctuation">.</span><span class="token function">unshift</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//unshift也有返回值，同push</span>

<span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//删除最后一个元素，不跟参数，一次只能一个</span>
    arr<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>      <span class="token comment" spellcheck="true">//  pop完毕后会返回删除的元素</span>

<span class="token function">shift</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  删除第一个元素    一次一个，有返回值，不带参数
    arr<span class="token punctuation">.</span><span class="token function">shift</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    

<span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">//通过元素返回数组索引</span>
    <span class="token keyword">var</span> arr<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    arr<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//返回该元素索引号，只返回第一个，找不到则返回-1</span>
    arr<span class="token punctuation">.</span><span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//从后往前查找</span>

<span class="token function">charAt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//通过索引返回数组元素</span>

<span class="token function">toLocalString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//将数组转化为本地化字符串</span>
<span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>          <span class="token comment" spellcheck="true">//转化为字符串</span>
</code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//map方法将数组的所有成员依次传入参数函数，然后把每一次的执行结果组成一个新数组返回。</span>
<span class="token keyword">var</span> numbers <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

numbers<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>n<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> n <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// [2, 3, 4]</span>

numbers
<span class="token comment" spellcheck="true">// [1, 2, 3] </span>

map方法接受一个函数作为参数。该函数调用时，map方法向它传入三个参数：当前成员、当前位置和数组本身。
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>elem<span class="token punctuation">,</span> index<span class="token punctuation">,</span> arr<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> elem <span class="token operator">*</span> index<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// [0, 2, 6] 返回新数组</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">,</span><span class="token keyword">this</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//对数组内每个元素都调用一次函数，没有返回值</span>
<span class="token keyword">var</span> a<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
a<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span>i<span class="token punctuation">,</span>a<span class="token punctuation">)</span><span class="token punctuation">{</span>a<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token operator">++</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>      <span class="token comment" spellcheck="true">//a现在是[2,3,4]</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">,</span><span class="token keyword">this</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//满足条件的返回到新数组，传入的第二格参数为this指向</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">return</span> x<span class="token operator">></span><span class="token number">1</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//[2,3]</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">every</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">,</span><span class="token keyword">this</span><span class="token punctuation">)</span>       <span class="token comment" spellcheck="true">//判断数组中是否每个元素都满足条件，是true否false，[]空数组总返回true</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">every</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">return</span> x<span class="token operator">&lt;</span><span class="token number">4</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>         <span class="token comment" spellcheck="true">//true</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">some</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">,</span><span class="token keyword">this</span><span class="token punctuation">)</span>       <span class="token comment" spellcheck="true">//判断数组中是否有满足条件的元素，有true无false，[]空数组返回false</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">some</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">return</span> x<span class="token operator">></span><span class="token number">5</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>        <span class="token comment" spellcheck="true">//true</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//每次将前两个参数合并作为新第一个参数</span>
<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">reduce</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span>y<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">return</span> x<span class="token operator">*</span>y<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//24:((1*2)*3)*4</span>
<span class="token function">reduceRight</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">,</span><span class="token number">60</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">reduceRight</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span>y<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">return</span> x<span class="token operator">/</span>y<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//3:(60/10)/2</span></code></pre>
<h3 id="Function对象方法"><a href="#Function对象方法" class="headerlink" title="Function对象方法"></a>Function对象方法</h3><pre><code></code></pre><h3 id="String对象方法"><a href="#String对象方法" class="headerlink" title="String对象方法"></a>String对象方法</h3><pre class=" language-js"><code class="language-js">String<span class="token punctuation">.</span><span class="token function">charAt</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">//返回字符串中的第n个字符</span>
String<span class="token punctuation">.</span><span class="token function">charCodeAt</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//返回字符串中的第n个字符的代码</span>
String<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>字符串<span class="token number">1</span><span class="token punctuation">,</span>字符串<span class="token number">2</span><span class="token punctuation">,</span><span class="token operator">...</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//连接字符串,返回新字符串</span>
String<span class="token punctuation">.</span><span class="token function">fromCharCode</span><span class="token punctuation">(</span><span class="token number">65</span><span class="token punctuation">,</span><span class="token number">66</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//从字符编码创建字符串 AB</span>
String<span class="token punctuation">.</span><span class="token function">index0f</span><span class="token punctuation">(</span>要找的字符串<span class="token punctuation">,</span>从某个位置开始的索引<span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回的是这个字符串的索引值,没找到则返回-1</span>
String<span class="token punctuation">.</span><span class="token function">lastIndex0f</span><span class="token punctuation">(</span>要找的字符串<span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//从后向前找,但是索引仍然是从左向右的方式,找不到则返回-1</span>
String<span class="token punctuation">.</span>length   <span class="token comment" spellcheck="true">//字符串的长度</span>
String<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token regex">/abc/g</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//找到一个或多个正则表达式的匹配</span>
String<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">"Microsoft"</span><span class="token punctuation">,</span><span class="token string">"Runoob"</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//替换一个与正则表达式匹配的子串，只替换一次</span>
String<span class="token punctuation">.</span><span class="token function">search</span><span class="token punctuation">(</span><span class="token string">"Runoob"</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//检索与正则表达式相匹配的子串，返回位置索引值</span>
String<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//截取字符串，包头不包尾，同数组截取</span>

String<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//将字符串分割成字符串数组</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'|'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["a", "b", "c"]</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["a", "|", "b", "|", "c"]</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["a|b|c"]</span>
    <span class="token string">'a||c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'|'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ['a', '', 'c']</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'|'</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// [] 第二个参数限制返回个数</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'|'</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["a"]</span>
    <span class="token string">'a|b|c'</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'|'</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// ["a", "b"]</span>
<span class="token comment" spellcheck="true">//Array.join()与String.split()互为逆运算</span>

String<span class="token punctuation">.</span><span class="token function">substr</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//抽取一个子串，（开始，长度）</span>
String<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//返回字符串的一个子串，包头不包尾，截取</span>
String<span class="token punctuation">.</span><span class="token function">toLocaleLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//把字符串转换小写</span>
String<span class="token punctuation">.</span><span class="token function">toLocaleUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//将字符串转换成大写</span>
String<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//将字符串转换成小写</span>
String<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回字符串</span>
String<span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//将字符串转换成大写</span>
？？？？？
String<span class="token punctuation">.</span><span class="token function">value0f</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回字符串</span>
</code></pre>
<h3 id="Math对象方法"><a href="#Math对象方法" class="headerlink" title="Math对象方法"></a>Math对象方法</h3><pre class=" language-js"><code class="language-js">Math<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//计算绝对值</span>
Math<span class="token punctuation">.</span><span class="token function">acos</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//计算反余弦值</span>
Math<span class="token punctuation">.</span><span class="token function">asin</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//计算反正弦值</span>
Math<span class="token punctuation">.</span><span class="token function">atan</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//计算反正切值</span>
Math<span class="token punctuation">.</span><span class="token function">atan2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//计算从x轴到一个点之间的角度</span>
Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//对一个数上舍入，即取整加1</span>
    Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span><span class="token number">3.2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 4</span>
    Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">3.2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// -3</span>
Math<span class="token punctuation">.</span><span class="token function">cos</span><span class="token punctuation">(</span><span class="token punctuation">)</span>       <span class="token comment" spellcheck="true">//计算余弦值</span>
Math<span class="token punctuation">.</span>E           <span class="token comment" spellcheck="true">//算术常量e,即自然对数的底数（约等于2.718）</span>
Math<span class="token punctuation">.</span><span class="token function">exp</span><span class="token punctuation">(</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//返回 E 的 x 次幂的值</span>
Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token punctuation">)</span>    <span class="token comment" spellcheck="true">//对一个数下舍入，即取整</span>
    Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token number">3.2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// 3</span>
    Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">3.2</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// -4</span>
Math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回数的自然对数（底为e）</span>
Math<span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回最大的参数</span>
Math<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回最小的参数</span>
Math<span class="token punctuation">.</span>PI          <span class="token comment" spellcheck="true">//返回圆周率（约等于3.14159）</span>
Math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span>y<span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//返回 x 的 y 次幂</span>
Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>     <span class="token comment" spellcheck="true">//返回介于0（包含）~1（不包含）之间的一个随机数</span>
Math<span class="token punctuation">.</span><span class="token function">round</span><span class="token punctuation">(</span><span class="token punctuation">)</span>      <span class="token comment" spellcheck="true">//四舍五入</span>
Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>       <span class="token comment" spellcheck="true">//返回数的平方根</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">//得到一个两数之间的随机整数，包括两个数在内</span>
<span class="token keyword">function</span> <span class="token function">getRandom</span><span class="token punctuation">(</span>min<span class="token punctuation">,</span> max<span class="token punctuation">)</span> <span class="token punctuation">{</span>
 <span class="token keyword">return</span> Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token punctuation">(</span>max <span class="token operator">-</span> min <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">+</span> min<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">//0到num</span>
Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token punctuation">(</span>num <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="Data对象方法"><a href="#Data对象方法" class="headerlink" title="Data对象方法"></a>Data对象方法</h3><pre class=" language-js"><code class="language-js"><span class="token function">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//无论有无参数，总是返回当前时间</span>
<span class="token comment" spellcheck="true">// "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"</span>
<span class="token function">Date</span><span class="token punctuation">(</span><span class="token number">2000</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">// "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"</span></code></pre>
<p>Date实例有一个独特的地方。其他对象求值的时候，都是默认调用.valueOf()方法，但是Date实例求值的时候，默认调用的是toString()方法。这导致对Date实例求值，返回的是一个字符串，代表该实例对应的时间。</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> today <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
today
<span class="token comment" spellcheck="true">// "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"</span>
<span class="token comment" spellcheck="true">// 等同于</span>
today<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">// "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"</span>

<span class="token comment" spellcheck="true">// 参数为时间零点开始计算的毫秒数</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token number">1378218728000</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">// Tue Sep 03 2013 22:32:08 GMT+0800 (CST)</span>
<span class="token comment" spellcheck="true">// 参数为日期字符串</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'January 6, 2013'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// Sun Jan 06 2013 00:00:00 GMT+0800 (CST)</span>
<span class="token comment" spellcheck="true">// 参数为多个整数，</span>
<span class="token comment" spellcheck="true">// 代表年、月、日、小时、分钟、秒、毫秒</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token number">2013</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">// Tue Jan 01 2013 00:00:00 GMT+0800 (CST)</span>

<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'2013-2-15'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'2013/2/15'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'02/15/2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'2013-FEB-15'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'FEB, 15, 2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'FEB 15, 2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'February, 15, 2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'February 15, 2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'15 Feb 2013'</span><span class="token punctuation">)</span>
<span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token string">'15, February, 2013'</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">// Fri Feb 15 2013 00:00:00 GMT+0800 (CST)</span>
<span class="token comment" spellcheck="true">//具体传参见文档，此为了解内容https://wangdoc.com/javascript/stdlib/date.html</span>

<span class="token function">Data</span><span class="token punctuation">(</span><span class="token punctuation">)</span>日期对象  是一个构造函数，必须使用<span class="token keyword">new</span>调用创建日期对象
    <span class="token keyword">var</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">//有参数则返回参数时间 '2020-8-4'或'2020/8/4' 字符串形式</span>
    <span class="token keyword">var</span> year <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getFullYear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> month <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getMonth</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>      <span class="token comment" spellcheck="true">//返回月 0-11</span>
    <span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'星期日'</span><span class="token punctuation">,</span> <span class="token string">'星期一'</span><span class="token punctuation">,</span> <span class="token string">'星期二'</span><span class="token punctuation">,</span> <span class="token string">'星期三'</span><span class="token punctuation">,</span> <span class="token string">'星期四'</span><span class="token punctuation">,</span> <span class="token string">'星期五'</span><span class="token punctuation">,</span> <span class="token string">'星期六'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> day <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getDay</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>        <span class="token comment" spellcheck="true">// 1-6 星期日为 0</span>
    <span class="token keyword">var</span> oneday <span class="token operator">=</span> arr<span class="token punctuation">[</span>day<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> hour <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getHours</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> h <span class="token operator">=</span> hour <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> hour <span class="token punctuation">:</span> hour<span class="token punctuation">;</span>
    <span class="token keyword">var</span> min <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getMinutes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> s <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getSeconds</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>date<span class="token punctuation">)</span><span class="token punctuation">;</span>

    返回当前时间函数
    <span class="token keyword">function</span> <span class="token function">getTimer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> hour <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getHours</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> hour <span class="token operator">=</span> hour <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> hour <span class="token punctuation">:</span> hour<span class="token punctuation">;</span>
        <span class="token keyword">var</span> min <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getMinutes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> min <span class="token operator">=</span> min <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> min <span class="token punctuation">:</span> min<span class="token punctuation">;</span>
        <span class="token keyword">var</span> s <span class="token operator">=</span> date<span class="token punctuation">.</span><span class="token function">getSeconds</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> s <span class="token operator">=</span> s <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> s <span class="token punctuation">:</span> s<span class="token punctuation">;</span>
        <span class="token keyword">return</span> hour <span class="token operator">+</span> <span class="token string">':'</span> <span class="token operator">+</span> min <span class="token operator">+</span> <span class="token string">':'</span> <span class="token operator">+</span> s<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">getTimer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        时间戳
        <span class="token keyword">var</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//第一种方法</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>date<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//获取现在距离1970年1月1日过的毫秒数</span>
        <span class="token comment" spellcheck="true">//第二种方法</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>date<span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">//valueOf()与getTime效果相同</span>
        <span class="token comment" spellcheck="true">//第三种方法</span>
        <span class="token keyword">var</span> date1 <span class="token operator">=</span> <span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//第四种方法 H5新增</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>Date<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        时分秒转换公式
        d <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>总秒数 <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">24</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//计算天数</span>
        h <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>总秒数 <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">%</span> <span class="token number">24</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//计算小时</span>
        m <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>总秒数 <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">%</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">//计算分钟</span>
        s <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>总秒数 <span class="token operator">%</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span>        <span class="token comment" spellcheck="true">//计算当前秒数</span>

        封装倒计时函数
        <span class="token keyword">function</span> <span class="token function">countDown</span><span class="token punctuation">(</span>time<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">var</span> nowTime <span class="token operator">=</span> <span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">var</span> inputTime <span class="token operator">=</span> <span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span>time<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">var</span> times <span class="token operator">=</span> <span class="token punctuation">(</span>inputTime <span class="token operator">-</span> nowTime<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">1000</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//1秒=1000毫秒</span>
            d <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>times <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">24</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//计算天数      取整parseInt()</span>
            d <span class="token operator">=</span> d <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> d <span class="token punctuation">:</span> d<span class="token punctuation">;</span>
            h <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>times <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">%</span> <span class="token number">24</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//计算小时</span>
            h <span class="token operator">=</span> h <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> h <span class="token punctuation">:</span> h<span class="token punctuation">;</span>
            m <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>times <span class="token operator">/</span> <span class="token number">60</span> <span class="token operator">%</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">//计算分钟</span>
            m <span class="token operator">=</span> m <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> m <span class="token punctuation">:</span> m<span class="token punctuation">;</span>
            s <span class="token operator">=</span> <span class="token function">parseInt</span><span class="token punctuation">(</span>times <span class="token operator">%</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            s <span class="token operator">=</span> s <span class="token operator">&lt;</span> <span class="token number">10</span> <span class="token operator">?</span> <span class="token string">'0'</span> <span class="token operator">+</span> s <span class="token punctuation">:</span> s<span class="token punctuation">;</span>
            <span class="token keyword">return</span> d <span class="token operator">+</span> <span class="token string">'天'</span> <span class="token operator">+</span> h <span class="token operator">+</span> <span class="token string">'时'</span> <span class="token operator">+</span> m <span class="token operator">+</span> <span class="token string">'分'</span> <span class="token operator">+</span> s <span class="token operator">+</span> <span class="token string">'秒'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">countDown</span><span class="token punctuation">(</span><span class="token string">'2020-12-1 14:00:00'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="原型与原型链"><a href="#原型与原型链" class="headerlink" title="原型与原型链"></a>原型与原型链</h3><p><strong>所有 JavaScript 对象都从原型继承属性和方法</strong></p>
<p>原型继承</p>
<p>所有 JavaScript 对象都从原型继承属性和方法。</p>
<p>日期对象继承自 Date.prototype。数组对象继承自 Array.prototype。Person 对象继承自 Person.prototype。</p>
<p>Object.prototype 位于原型继承链的顶端：</p>
<p>日期对象、数组对象和 Person 对象都继承自 Object.prototype。</p>
<h3 id="箭头函数与函数中的this"><a href="#箭头函数与函数中的this" class="headerlink" title="箭头函数与函数中的this"></a>箭头函数与函数中的this</h3><h3 id="作用域与变量提升"><a href="#作用域与变量提升" class="headerlink" title="作用域与变量提升"></a>作用域与变量提升</h3><p>在ES6之前，JavaScript没有块级作用域(一对花括号{}即为一个块级作用域)，只有全局作用域和函数作用域。</p>
<p>变量提升即将变量声明提升到它所在作用域的最开始的部分。</p>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">//函数提升</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>  <span class="token comment" spellcheck="true">// f a() { console.log(a) }</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span> <span class="token comment" spellcheck="true">//undefined</span>
<span class="token keyword">function</span> <span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span> 
<span class="token punctuation">}</span>
<span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">//相当于</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token string">'function'</span>
<span class="token keyword">var</span> b
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true">//函数提升与变量提升的优先级</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">// f a() {console.log(10)}</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">//  undefined</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">//10</span>
<span class="token punctuation">}</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//3</span>
a <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//a is not a function;</span>
<span class="token comment" spellcheck="true">//相当于</span>
    <span class="token keyword">var</span> a <span class="token operator">=</span> funtion <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">var</span> a<span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">// f a() {console.log(10)}</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//  undefined</span>
    a <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>   <span class="token comment" spellcheck="true">//3</span>
    a <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment" spellcheck="true">//a() is not a function;</span></code></pre>
<p>可见函数提升要比变量提升的优先级要高一些，且不会被变量声明覆盖，但是会被变量赋值之后覆盖。</p>
<h3 id="闭包"><a href="#闭包" class="headerlink" title="闭包"></a>闭包</h3><p>闭包特性：</p>
<ol>
<li>函数嵌套函数</li>
<li>函数内部可以引用函数外部的参数和变量</li>
<li>参数和变量不会被垃圾回收机制回收</li>
</ol>
<pre class=" language-js"><code class="language-js">  <span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">var</span> num <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
            num<span class="token operator">++</span><span class="token punctuation">;</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">var</span> n <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
                console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token operator">++</span>n<span class="token punctuation">)</span><span class="token punctuation">;</span>
                console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token operator">++</span>num<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">var</span> ff <span class="token operator">=</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">ff</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">ff</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//</span></code></pre>
<p>一般情况下，在函数fn执行完后，就应该连同它里面的变量一同被销毁，但是在这个例子中，匿名函数作为fn的返回值被赋值给了fn1，这时候相当于fn1=function(){var n = 0 … }，并且匿名函数内部引用着fn里的变量num，所以变量num无法被销毁，而变量n是每次被调用时新创建的，所以每次fn1执行完后它就把属于自己的变量连同自己一起销毁，最后就剩下孤零零的num，于是这里就产生了内存消耗的问题</p>
<h3 id="深拷贝与浅拷贝"><a href="#深拷贝与浅拷贝" class="headerlink" title="深拷贝与浅拷贝"></a>深拷贝与浅拷贝</h3><pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">// 实现浅拷贝(只拷贝一层，如果里面包含object类型则只拷贝了地址)</span>
        <span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
            id<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
            name<span class="token punctuation">:</span> <span class="token string">'andy'</span><span class="token punctuation">,</span>
            a<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            msg<span class="token punctuation">:</span> <span class="token punctuation">{</span>
                age<span class="token punctuation">:</span> <span class="token number">18</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> ob <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> k <span class="token keyword">in</span> obj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            o<span class="token punctuation">[</span>k<span class="token punctuation">]</span> <span class="token operator">=</span> obj<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>ob<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment" spellcheck="true">// ES6新方法</span>
        Object<span class="token punctuation">.</span><span class="token function">assign</span><span class="token punctuation">(</span>oo<span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">// 实现深拷贝</span>
        <span class="token keyword">var</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>
            id<span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
            name<span class="token punctuation">:</span> <span class="token string">'andy'</span><span class="token punctuation">,</span>
            a<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            msg<span class="token punctuation">:</span> <span class="token punctuation">{</span>
                age<span class="token punctuation">:</span> <span class="token number">18</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//封装函数</span>
        <span class="token keyword">function</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>newObj<span class="token punctuation">,</span> oldObj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> k <span class="token keyword">in</span> oldObj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment" spellcheck="true">// 获取原对象每个属性值</span>
                <span class="token keyword">var</span> item <span class="token operator">=</span> oldObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">;</span>
                <span class="token comment" spellcheck="true">// 判断属性值属于哪种数据类型</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>item <span class="token keyword">instanceof</span> <span class="token class-name">Array</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment" spellcheck="true">// 如果为数组通过递归再一次执行for in，遍历数组</span>
                    newObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
                    <span class="token function">deepCopy</span><span class="token punctuation">(</span>newObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">,</span> item<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token comment" spellcheck="true">// 这里需要先判断数组，因为数组类型返回值是object</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>item <span class="token keyword">instanceof</span> <span class="token class-name">Object</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment" spellcheck="true">// 如果为对象则递归再一次遍历判断</span>
                    newObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
                    <span class="token function">deepCopy</span><span class="token punctuation">(</span>newObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span><span class="token punctuation">,</span> item<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                    <span class="token comment" spellcheck="true">// 普通数据类型直接添加</span>
                    newObj<span class="token punctuation">[</span>k<span class="token punctuation">]</span> <span class="token operator">=</span> item<span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">// 不需要返回值，执行完毕后newObj已经达到想要的效果</span>
        <span class="token function">deepCopy</span><span class="token punctuation">(</span>o<span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="DOM"><a href="#DOM" class="headerlink" title="DOM"></a>DOM</h3><p><code>nodeType</code>属性返回一个整数值，表示节点的类型。不同节点的<code>nodeType</code>属性值和对应的常量如下。</p>
<ul>
<li>文档节点（document）：9，对应常量<code>Node.DOCUMENT_NODE</code></li>
<li>元素节点（element）：1，对应常量<code>Node.ELEMENT_NODE</code></li>
<li>属性节点（attr）：2，对应常量<code>Node.ATTRIBUTE_NODE</code></li>
<li>文本节点（text）：3，对应常量<code>Node.TEXT_NODE</code></li>
<li>文档片断节点（DocumentFragment）：11，对应常量<code>Node.DOCUMENT_FRAGMENT_NODE</code></li>
<li>文档类型节点（DocumentType）：10，对应常量<code>Node.DOCUMENT_TYPE_NODE</code></li>
<li>注释节点（Comment）：8，对应常量<code>Node.COMMENT_NODE</code></li>
</ul>
<pre><code>Node.ELEMENT_NODE == 1
Node.ATTRIBUTE_NODE == 2
Node.TEXT_NODE == 3
Node.CDATA_SECTION_NODE == 4
Node.ENTITY_REFERENCE_NODE == 5
Node.ENTITY_NODE == 6
Node.PROCESSING_INSTRUCTION_NODE == 7
Node.COMMENT_NODE == 8
Node.DOCUMENT_NODE == 9
Node.DOCUMENT_TYPE_NODE == 10
Node.DOCUMENT_FRAGMENT_NODE == 11
Node.NOTATION_NODE == 12</code></pre><pre><code>document.nodeType // 9
document.nodeType === Node.DOCUMENT_NODE // true</code></pre><p><code>nodeValue</code>属性返回一个字符串，表示当前节点本身的文本值，该属性可读写。</p>
<p>只有文本节点（text）、注释节点（comment）和属性节点（attr）有文本值，因此这三类节点的<code>nodeValue</code>可以返回结果，其他类型的节点一律返回<code>null</code></p>
<p><code>textContent</code>属性返回当前节点和它的所有后代节点的文本内容。</p>
<pre><code>// HTML 代码为
// &lt;div id=&quot;divA&quot;&gt;This is &lt;span&gt;some&lt;/span&gt; text&lt;/div&gt;

document.getElementById(&#39;divA&#39;).textContent
// This is some text</code></pre><p><code>textContent</code>属性自动忽略当前节点内部的 HTML 标签，返回所有文本内容</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td></td>
<td>nodeName</td>
<td>nodeType</td>
<td>nodeValue</td>
</tr>
<tr>
<td>文档节点</td>
<td>#document</td>
<td>9</td>
<td>null</td>
</tr>
<tr>
<td>元素节点</td>
<td>标签名（大写）</td>
<td>1</td>
<td>null</td>
</tr>
<tr>
<td>属性节点</td>
<td>属性名</td>
<td>2</td>
<td>属性值</td>
</tr>
<tr>
<td>文本节点</td>
<td>#text</td>
<td>3</td>
<td>文本内容</td>
</tr>
</tbody></table>
<p>更多参考<a href="https://wangdoc.com/javascript/dom/node.html" target="_blank" rel="noopener">https://wangdoc.com/javascript/dom/node.html</a></p>
<p>页面加载完毕后执行js代码</p>
<p>window.onload=function(){}</p>
<p>node接口</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>获取节点</td>
<td></td>
</tr>
<tr>
<td>document.getElementById(‘id’)</td>
<td>返回带有指定 ID 的元素。</td>
</tr>
<tr>
<td>document.getElementsByTagName(‘div’)</td>
<td>返回包含带有指定<strong>标签名</strong>称的所有元素的节点列表（集合/节点数组）。</td>
</tr>
<tr>
<td>document.getElementsByClassName(‘class’)</td>
<td>返回包含带有指定<strong>类名</strong>的所有元素的节点列表。</td>
</tr>
<tr>
<td>document.getElementsByName(‘name’)</td>
<td>通过name属性获取一组元素节点对象</td>
</tr>
<tr>
<td>document.querySelector(‘#id’)/(‘.class’)</td>
<td>找到第一个符合条件的节点对象</td>
</tr>
<tr>
<td>document.querySelectorAll(‘#id’)</td>
<td>找到所有符合节点</td>
</tr>
<tr>
<td>查找节点</td>
<td></td>
</tr>
<tr>
<td>parentNode.firstChild</td>
<td>第一个子节点</td>
</tr>
<tr>
<td>parentNode.lastChild</td>
<td>最后一个子节点</td>
</tr>
<tr>
<td>parentNode.childNodes</td>
<td>所有子节点（包含文本节点等）</td>
</tr>
<tr>
<td><strong>node.children</strong></td>
<td>所有子元素节点</td>
</tr>
<tr>
<td>node.parentNode</td>
<td>父节点</td>
</tr>
<tr>
<td>node.nextSibling</td>
<td>下一个兄弟节点</td>
</tr>
<tr>
<td>node.previousSibling</td>
<td>前一个兄弟节点</td>
</tr>
<tr>
<td>创建节点</td>
<td></td>
</tr>
<tr>
<td>document.createElement(‘elementName’)</td>
<td>创建元素节点</td>
</tr>
<tr>
<td>document.createAttribute(‘attrName’)</td>
<td>创建属性节点</td>
</tr>
<tr>
<td>document.createTextNode(‘test’)</td>
<td>创建文本节点</td>
</tr>
<tr>
<td>document.createComment(‘comment’)</td>
<td>创建注释节点</td>
</tr>
<tr>
<td>添加节点</td>
<td></td>
</tr>
<tr>
<td>node.appendChild(‘element/txt/comment/fragment’)</td>
<td>添加新的节点或移动已有的节点到指定节点下作为子节点</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>replaceChild()</td>
<td>替换子节点。</td>
</tr>
<tr>
<td>.insertBefore()</td>
<td>在指定的子节点前面插入新的子节点。</td>
</tr>
<tr>
<td>removeChild(‘’)</td>
<td>删除子节点。</td>
</tr>
<tr>
<td>remove()</td>
<td>删除自身</td>
</tr>
<tr>
<td>getAttribute(‘name’)</td>
<td>返回指定的属性值。</td>
</tr>
<tr>
<td>setAttribute(‘class’,’newclass’)</td>
<td>把指定属性设置或修改为指定的值。</td>
</tr>
</tbody></table>
<p>使用 <a href="https://www.runoob.com/jsref/met-node-issamenode.html" target="_blank" rel="noopener">isSameNode() 方法</a>来确定两个节点是否相同。</p>
<p>使用 <a href="https://www.runoob.com/jsref/met-node-isequalnode.html" target="_blank" rel="noopener">isEqualNode() 方法</a> 检查两个节点是否相等，但不一定是相同的节点。</p>
<h5 id="文档节点（document）https-wangdoc-com-javascript-dom-document-html"><a href="#文档节点（document）https-wangdoc-com-javascript-dom-document-html" class="headerlink" title="文档节点（document）https://wangdoc.com/javascript/dom/document.html"></a>文档节点（document）<a href="https://wangdoc.com/javascript/dom/document.html" target="_blank" rel="noopener">https://wangdoc.com/javascript/dom/document.html</a></h5><p>document是一个对象，属于window对象的属性</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> doctype <span class="token operator">=</span> document<span class="token punctuation">.</span>doctype<span class="token punctuation">;</span>
doctype <span class="token comment" spellcheck="true">// "&lt;!DOCTYPE html>"</span>
doctype<span class="token punctuation">.</span>name <span class="token comment" spellcheck="true">// "html"</span>
<span class="token comment" spellcheck="true">//document.firstChild通常就返回这个节点。</span>
    <span class="token comment" spellcheck="true">//DOM树的根节点是html</span>
document<span class="token punctuation">.</span>documentElement  <span class="token comment" spellcheck="true">//返回html元素对象</span>
document<span class="token punctuation">.</span>body   <span class="token comment" spellcheck="true">//返回body元素对象</span>
document<span class="token punctuation">.</span>head  <span class="token comment" spellcheck="true">//指向&lt;head>节点</span>

document<span class="token punctuation">.</span>scrollingElement  <span class="token comment" spellcheck="true">//属性返回文档的滚动元素</span>
document<span class="token punctuation">.</span>activeElement    <span class="token comment" spellcheck="true">//属性返回获得当前焦点（focus）的 DOM 元素,通常，这个属性返回的是&lt;input>、&lt;textarea>、&lt;select>等表单元素</span>
</code></pre>
<h6 id="属性节点（element）https-wangdoc-com-javascript-dom-element-html"><a href="#属性节点（element）https-wangdoc-com-javascript-dom-element-html" class="headerlink" title="属性节点（element）https://wangdoc.com/javascript/dom/element.html"></a>属性节点（element）<a href="https://wangdoc.com/javascript/dom/element.html" target="_blank" rel="noopener">https://wangdoc.com/javascript/dom/element.html</a></h6><p>操作元素</p>
<p>element.innerText  //设置文本，去除空格和换行</p>
<p>element.innerHTML  //保留空格和换行，可执行标签</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>只可读取，一般相对于offsetParent计算</td>
<td></td>
</tr>
<tr>
<td>element.offsetHeight</td>
<td>返回元素的高度。</td>
</tr>
<tr>
<td>element.offsetWidth</td>
<td>返回元素的宽度。</td>
</tr>
<tr>
<td>element.offsetLeft</td>
<td>返回元素的水平偏移位置。</td>
</tr>
<tr>
<td>element.offsetParent</td>
<td>返回元素的偏移容器。</td>
</tr>
<tr>
<td>element.offsetTop</td>
<td>返回元素的垂直偏移位置。</td>
</tr>
<tr>
<td>常用于滚动监听</td>
<td></td>
</tr>
<tr>
<td>element.scrollHeight</td>
<td>返回元素的整体高度。</td>
</tr>
<tr>
<td>element.scrollLeft</td>
<td>返回元素左边缘与视图之间的距离。</td>
</tr>
<tr>
<td>element.scrollTop</td>
<td>返回元素上边缘与视图之间的距离。</td>
</tr>
<tr>
<td>element.scrollWidth</td>
<td>返回元素的整体宽度。</td>
</tr>
</tbody></table>
<p>更多属性见文档：<a href="https://www.w3school.com.cn/jsref/dom_obj_all.asp" target="_blank" rel="noopener">https://www.w3school.com.cn/jsref/dom_obj_all.asp</a></p>
<h4 id="控制样式"><a href="#控制样式" class="headerlink" title="控制样式"></a>控制样式</h4><pre class=" language-js"><code class="language-js"><span class="token number">1</span><span class="token punctuation">.</span>使用style
<span class="token comment" spellcheck="true">//style.height只能读写行内样式，是字符串类型，带单位；</span>
<span class="token comment" spellcheck="true">//这里修改类名的时候要用style.className</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token number">2</span><span class="token punctuation">.</span>添加类名更改样式
div1<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">"active"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//添加class样式</span>
div1<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">"box"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//删除class样式</span>
div1<span class="token punctuation">.</span>classList<span class="token punctuation">.</span><span class="token function">toggle</span><span class="token punctuation">(</span><span class="token string">"show"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//切换class样式</span></code></pre>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">/*通用的获取元素样式的方法*/</span>
    <span class="token keyword">function</span> <span class="token function">getStyle</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>window<span class="token punctuation">.</span>getComputedStyle<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment" spellcheck="true">//正常浏览器的方式，具有getComputedStyle()方法</span>
            <span class="token keyword">return</span> <span class="token function">getComputedStyle</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            <span class="token comment" spellcheck="true">//IE8的方式，没有getComputedStyle()方法</span>
            <span class="token keyword">return</span> obj<span class="token punctuation">.</span>currentStyle<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">var</span> box <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"box"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">getStyle</span><span class="token punctuation">(</span>box<span class="token punctuation">,</span> <span class="token string">"width"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<table>
<thead>
<tr>
<th>鼠标事件</th>
<th>描述</th>
<th>dom</th>
</tr>
</thead>
<tbody><tr>
<td>onclick</td>
<td>单击</td>
<td>2</td>
</tr>
<tr>
<td>ondblclick</td>
<td>双击</td>
<td>2</td>
</tr>
<tr>
<td>onmousedown</td>
<td>鼠标按下</td>
<td>2</td>
</tr>
<tr>
<td>onmouseup</td>
<td>鼠标松开</td>
<td>2</td>
</tr>
<tr>
<td>onmouseover</td>
<td>鼠标移到元素</td>
<td>2</td>
</tr>
<tr>
<td>onmousemove</td>
<td>鼠标在元素内移动</td>
<td>2</td>
</tr>
<tr>
<td>onmouseout</td>
<td>鼠标移出元素</td>
<td>2</td>
</tr>
<tr>
<td>onmouseenter</td>
<td>鼠标移到元素（不支持冒泡）</td>
<td>2</td>
</tr>
<tr>
<td>onmouseleave</td>
<td>鼠标移出元素（不支持冒泡）</td>
<td>2</td>
</tr>
<tr>
<td>oncontextmenu</td>
<td>鼠标右键打开菜单</td>
<td></td>
</tr>
<tr>
<td>键盘事件</td>
<td>描述</td>
<td>dom</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>键盘事件</th>
<th>描述</th>
<th>dom</th>
</tr>
</thead>
<tbody><tr>
<td>onkeydown</td>
<td>键盘按键被按下</td>
<td>2</td>
</tr>
<tr>
<td>onkeypress</td>
<td>键盘按键按下并松开</td>
<td>2</td>
</tr>
<tr>
<td>onkeyup</td>
<td>键盘按键被松开</td>
<td>2</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>表单事件</th>
<th>描述</th>
<th>dom</th>
</tr>
</thead>
<tbody><tr>
<td>onblur</td>
<td>元素失去焦点时触发</td>
<td>2</td>
</tr>
<tr>
<td>onchange</td>
<td>该事件在表单元素的内容改变时触发( input, keygen, select, 和 textarea)</td>
<td>2</td>
</tr>
<tr>
<td>onfocus</td>
<td>元素获取焦点时触发</td>
<td>2</td>
</tr>
<tr>
<td>onfocusin</td>
<td>元素即将获取焦点时触发</td>
<td>2</td>
</tr>
<tr>
<td>onfocusout</td>
<td>元素即将失去焦点时触发</td>
<td>2</td>
</tr>
<tr>
<td>oninput</td>
<td>元素获取用户输入时触发</td>
<td>3</td>
</tr>
<tr>
<td>onreset</td>
<td>表单重置时触发</td>
<td>2</td>
</tr>
<tr>
<td>onsearch</td>
<td>用户向搜索域输入文本时触发（input=”search”）</td>
<td></td>
</tr>
<tr>
<td>onselect</td>
<td>用户选取文本时触发（input和textarea）</td>
<td>2</td>
</tr>
<tr>
<td>onsubmit</td>
<td>表单提交时触发</td>
<td>2</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>其他事件</th>
<th>描述</th>
<th>DOM</th>
</tr>
</thead>
<tbody><tr>
<td>onload</td>
<td>页面加载完毕（包括内容、图片、frame、object）的时候触发该事件</td>
<td></td>
</tr>
<tr>
<td>resize</td>
<td>页面大小改变的时候触发该事件（例如浏览器缩放）</td>
<td></td>
</tr>
<tr>
<td>scroll</td>
<td>页面滚动的时候触发该事件</td>
<td></td>
</tr>
<tr>
<td>unload</td>
<td>从页面或frame删除所有内容的时候触发该事件（例如离开一个页面）</td>
<td></td>
</tr>
</tbody></table>
<p>其他事件查表<a href="https://www.runoob.com/jsref/dom-obj-event.html" target="_blank" rel="noopener">https://www.runoob.com/jsref/dom-obj-event.html</a></p>
<table>
<thead>
<tr>
<th>数组</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>arguments[]</td>
<td>只定义在函数体中，是局部变量，在全局环境中为undefined</td>
</tr>
<tr>
<td>arguments.callee</td>
<td>指代当前执行函数</td>
</tr>
<tr>
<td>arguments.length</td>
<td>实际传入参数个数</td>
</tr>
</tbody></table>
<h3 id="延时器与定时器"><a href="#延时器与定时器" class="headerlink" title="延时器与定时器"></a>延时器与定时器</h3><pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">//延时器</span>
<span class="token keyword">var</span> time<span class="token operator">=</span><span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">clearTimeout</span><span class="token punctuation">(</span>time<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">//执行一个循环定时器，并将返回值赋给timer这个变量</span>
<span class="token keyword">var</span> timer <span class="token operator">=</span> <span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'2'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//取消定时器需要有索引值，timer保存的是动画队列里的索引值(key) ，clearInterval停止动画需要一个索引值</span>
<span class="token function">clearInterval</span><span class="token punctuation">(</span>timer<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h3><h5 id="Window：浏览器窗口，顶层对象"><a href="#Window：浏览器窗口，顶层对象" class="headerlink" title="Window：浏览器窗口，顶层对象"></a>Window：浏览器窗口，顶层对象</h5><p><code>window</code>对象不但充当全局作用域，而且表示浏览器窗口。</p>
<p><code>window</code>对象有<code>innerWidth</code>和<code>innerHeight</code>属性，可以获取浏览器窗口的内部宽度和高度。内部宽高是指除去菜单栏、工具栏、边框等占位元素后，用于显示网页的净宽高。</p>
<p>兼容性：IE&lt;=8不支持。</p>
<p>对应的，还有一个<code>outerWidth</code>和<code>outerHeight</code>属性，可以获取浏览器窗口的整个宽高。</p>
<p>window.open() ：打开新的窗口</p>
<p>window.close() ：关闭当前窗口</p>
<h5 id="History：历史记录-–-前进-后退"><a href="#History：历史记录-–-前进-后退" class="headerlink" title="History：历史记录  –  前进/后退"></a>History：历史记录  –  前进/后退</h5><ul>
<li>history.go()<ul>
<li>+n 为前进n页 类似浏览器的向前按钮</li>
<li>-n 为后退n页 类似浏览器的向后按钮</li>
</ul>
</li>
</ul>
<pre class=" language-js"><code class="language-js">history<span class="token punctuation">.</span><span class="token function">go</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">//向后退两页</span>
history<span class="token punctuation">.</span><span class="token function">go</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">//向前进一页</span></code></pre>
<ul>
<li>history.back() 加载 history 列表中的前一个 URL</li>
<li>history.forward(); 可以跳转到下一个页面</li>
</ul>
<pre class=" language-js"><code class="language-js">history<span class="token punctuation">.</span><span class="token function">back</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
history<span class="token punctuation">.</span><span class="token function">forward</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<ul>
<li>history.length 返回历史记录中有多少条记录</li>
</ul>
<h5 id="Navigator：访问者信息"><a href="#Navigator：访问者信息" class="headerlink" title="Navigator：访问者信息"></a>Navigator：访问者信息</h5><p>实现对浏览器类型的判断</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> ua <span class="token operator">=</span> navigator<span class="token punctuation">.</span>userAgent<span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token regex">/firefox/i</span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>ua<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"你是火狐浏览器"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token regex">/chrome/i</span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>ua<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"你是谷歌浏览器"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token regex">/msie/i</span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>ua<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"你是IE5-IE10浏览器"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">"ActiveXObject"</span> <span class="token keyword">in</span> window<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"你是IE11浏览器"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<h5 id="Screen：用户屏幕信息"><a href="#Screen：用户屏幕信息" class="headerlink" title="Screen：用户屏幕信息"></a>Screen：用户屏幕信息</h5><p>Screen 对象包含有关客户端显示屏幕的信息。</p>
<h5 id="Location：URL相关-–-页面跳转"><a href="#Location：URL相关-–-页面跳转" class="headerlink" title="Location：URL相关  –  页面跳转"></a>Location：URL相关  –  页面跳转</h5><p><code>location</code>对象表示当前页面的URL信息。例如，一个完整的URL：</p>
<pre><code>http://www.example.com:8080/path/index.html?a=1&amp;b=2#TOP</code></pre><p>可以用<code>location.href</code>获取。要获得URL各个部分的值，可以这么写：</p>
<pre><code>location.protocol; // &#39;http&#39;
location.host; // &#39;www.example.com&#39;
location.port; // &#39;8080&#39;
location.pathname; // &#39;/path/index.html&#39;
location.search; // &#39;?a=1&amp;b=2&#39;
location.hash; // &#39;TOP&#39;</code></pre><p>要加载一个新页面，可以调用<code>location.assign()</code>。如果要重新加载当前页面，调用<code>location.reload()</code>方法非常方便。</p>
<h3 id="正则表达式"><a href="#正则表达式" class="headerlink" title="正则表达式"></a>正则表达式</h3><pre class=" language-js"><code class="language-js">字面量定义
<span class="token keyword">var</span> reg <span class="token operator">=</span> <span class="token regex">/xyz/</span><span class="token punctuation">;</span>
构造函数定义
<span class="token keyword">var</span> reg <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RegExp</span><span class="token punctuation">(</span><span class="token string">'xyz'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> reg <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">RegExp</span><span class="token punctuation">(</span><span class="token regex">/xyz/</span><span class="token punctuation">,</span> <span class="token string">'i'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// 等价于</span>
<span class="token keyword">var</span> reg <span class="token operator">=</span> <span class="token regex">/xyz/i</span><span class="token punctuation">;</span>
后面参数：i  不区分大小写
        g  查找所有匹配项
        m  多行匹配

        <span class="token punctuation">[</span><span class="token operator">^</span>xyz<span class="token punctuation">]</span>表示除了x、y、z之外都可以匹配；<span class="token punctuation">[</span><span class="token operator">^</span><span class="token punctuation">]</span>，就表示匹配一切字符，其中包括换行符
                                                             <span class="token regex">/y((..)\2)\1/</span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span><span class="token string">'yabababab'</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">// true</span>
\<span class="token number">1</span>指向外层括号，\<span class="token number">2</span>指向内层括号

str<span class="token punctuation">.</span><span class="token function">search</span><span class="token punctuation">(</span>reg<span class="token punctuation">)</span><span class="token punctuation">;</span>
str<span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>reg<span class="token punctuation">)</span><span class="token punctuation">;</span>
b<span class="token punctuation">[</span>\s\S<span class="token punctuation">]</span>

  <span class="token punctuation">[</span>\u4e00<span class="token operator">-</span>\u9fa5<span class="token punctuation">]</span><span class="token operator">+</span></code></pre>
<table>
<thead>
<tr>
<th>元字符</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>^</td>
<td>匹配开头</td>
</tr>
<tr>
<td>$</td>
<td>匹配结尾</td>
</tr>
<tr>
<td>*</td>
<td>等价于{0,}</td>
</tr>
<tr>
<td>+</td>
<td>等价于{1,}</td>
</tr>
<tr>
<td>?</td>
<td>等价于{0,1}</td>
</tr>
<tr>
<td>.</td>
<td>匹配除换行符外的任一字符</td>
</tr>
<tr>
<td>()</td>
<td></td>
</tr>
<tr>
<td>x|y</td>
<td>x或者y</td>
</tr>
<tr>
<td>{m,n}</td>
<td>至少m次，至多n次</td>
</tr>
<tr>
<td>[xyz]</td>
<td>x或者y或者z</td>
</tr>
<tr>
<td>[^xyz]</td>
<td>除x或y或z外的任一字符</td>
</tr>
<tr>
<td>\d</td>
<td>等价于[0-9]</td>
</tr>
<tr>
<td>\D</td>
<td>等价于[^0-9]</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>\f</th>
<th>匹配一个换页符</th>
</tr>
</thead>
<tbody><tr>
<td>\n</td>
<td>匹配一个换行符</td>
</tr>
<tr>
<td>\r</td>
<td>匹配一个回车符</td>
</tr>
<tr>
<td>\t</td>
<td>匹配一个水平制表符</td>
</tr>
<tr>
<td>\s</td>
<td>匹配一个空白字符，包括空格，制表符，换页符，换行符相等于[ \t\r\n\v\f]</td>
</tr>
<tr>
<td>\S</td>
<td>匹配一个非空白字符相当于[^ \t\r\n\v\f]</td>
</tr>
<tr>
<td>\w</td>
<td>相当于[a-zA-Z0-9_]</td>
</tr>
<tr>
<td>\W</td>
<td>相当于[^a-zA-Z0-9_]</td>
</tr>
<tr>
<td>\1</td>
<td>匹配第一个()的内容</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>正则去重</p>
<pre class=" language-js"><code class="language-js"><span class="token keyword">var</span> str <span class="token operator">=</span> <span class="token string">'dfvgndsdddsss'</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>str<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex">/(\w)\1+/g</span><span class="token punctuation">,</span> <span class="token string">'$1'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h3><h3 id="AJAX"><a href="#AJAX" class="headerlink" title="AJAX"></a>AJAX</h3><p>node</p>
<p>npm -v  查看版本</p>
<h3 id="主要参考文档"><a href="#主要参考文档" class="headerlink" title="主要参考文档"></a>主要参考文档</h3><p>网道JavaScript教程：<a href="https://wangdoc.com/javascript/index.html" target="_blank" rel="noopener">https://wangdoc.com/javascript/index.html</a></p>
<p>MDN教程：<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript" target="_blank" rel="noopener">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript</a></p>
<p>现代JavaScript教程：<a href="https://zh.javascript.info/" target="_blank" rel="noopener">https://zh.javascript.info/</a></p>
<p>阮一峰ES6教程：<a href="https://wangdoc.com/es6/" target="_blank" rel="noopener">https://wangdoc.com/es6/</a></p>
<p>廖雪峰官方网站：<a href="https://www.liaoxuefeng.com/wiki/1022910821149312" target="_blank" rel="noopener">https://www.liaoxuefeng.com/wiki/1022910821149312</a></p>
<p>CSDN博主整理JavaScript全篇：<a href="https://blog.csdn.net/qq_38490457/article/details/109257751" target="_blank" rel="noopener">https://blog.csdn.net/qq_38490457/article/details/109257751</a></p>
<p>W3school教程：<a href="https://www.w3school.com.cn/" target="_blank" rel="noopener">https://www.w3school.com.cn/</a></p>
<p>菜鸟教程：<a href="https://www.runoob.com/js/js-tutorial.html" target="_blank" rel="noopener">https://www.runoob.com/js/js-tutorial.html</a></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">风栾</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://zzh0312.gitee.io/posts/45357.html">https://zzh0312.gitee.io/posts/45357.html</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">风栾</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/web%E5%89%8D%E7%AB%AF/">
                                    <span class="chip bg-color">web前端</span>
                                </a>
                            
                                <a href="/tags/HTML%E5%9F%BA%E7%A1%80/">
                                    <span class="chip bg-color">HTML基础</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'co0BUxGejd9ATTHU0ofThlQp-9Nh9j0Va',
        appKey: 'P0HtcTipPt7wyOTF8luYH3D4',
        notify: 'true' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: 'just go go'
    });
</script>

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/posts/49871.html">
                    <div class="card-image">
                        
                        <img src="https://img-blog.csdnimg.cn/20210104161132375.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p5ejAzMTIxOQ==,size_16,color_FFFFFF,t_70" class="responsive-img" alt="jQuery速查手册">
                        
                        <span class="card-title">jQuery速查手册</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            jQuery概述概述    jQuery是一种快速，简洁的JavaScript库。对代码进行了封装存放。宗旨是write less  do more。j是JavaScript ，query查询。常见的JavaScript库有juery，Pr
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2021-01-07
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/web%E5%89%8D%E7%AB%AF/" class="post-category">
                                    web前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/web%E5%89%8D%E7%AB%AF/">
                        <span class="chip bg-color">web前端</span>
                    </a>
                    
                    <a href="/tags/HTML%E5%9F%BA%E7%A1%80/">
                        <span class="chip bg-color">HTML基础</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/posts/10078.html">
                    <div class="card-image">
                        
                        <img src="https://img-blog.csdnimg.cn/20210104161132375.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3p5ejAzMTIxOQ==,size_16,color_FFFFFF,t_70" class="responsive-img" alt="CSS速查手册(持续更新中)">
                        
                        <span class="card-title">CSS速查手册(持续更新中)</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            css知识点速查&lt;!-- css基础
    1.什么是css？
        css的英文全称为Cascading Style Sheets，中文名为级联样式单，一般也称为层叠样式表单。
    2.css的功能？
       
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-12-17
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/web%E5%89%8D%E7%AB%AF/" class="post-category">
                                    web前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/web%E5%89%8D%E7%AB%AF/">
                        <span class="chip bg-color">web前端</span>
                    </a>
                    
                    <a href="/tags/HTML%E5%9F%BA%E7%A1%80/">
                        <span class="chip bg-color">HTML基础</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
    <div class="container row center-align" style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2020</span>
            <a href="/about" target="_blank">风栾</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">62.8k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2020";
                    var startMonth = "7";
                    var startDate = "16";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/Guard3120" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:3144857232@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=3144857232" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 3144857232" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"live2d-widget-model-haru"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false,"abbrlink":null,"alg":"crc16","crc16(default) and crc32 rep":"hex"},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>

</html>
